home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_224_mc_bush / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  7.3 KB  |  378 lines

  1. if(!init)
  2. {
  3.    orig_scale = _xscale;
  4.    hitarea._visible = 0;
  5.    walking = false;
  6.    parrying = false;
  7.    attacking = false;
  8.    jumping = false;
  9.    fall_distance = 0;
  10.    init = true;
  11.    side = "L";
  12.    lastdecision = 0;
  13.    deadcount = 0;
  14.    floor = 62;
  15.    walkdistance = 25;
  16.    reach = 45;
  17.    hit2_reach = 63;
  18.    damage = 20;
  19.    total_ki = 30;
  20.    ki = total_ki;
  21.    ki_cost = 10;
  22.    pushfactor = 2;
  23.    total_hp = 120;
  24.    hp = total_hp;
  25.    regen_rate = 0.3;
  26.    score = 1500;
  27.    _root.createPic("pic_bush",this);
  28. }
  29. attacking = false;
  30. speed = 0;
  31. walking = false;
  32. this.onEnterFrame = function()
  33. {
  34.    if(!init)
  35.    {
  36.       return undefined;
  37.    }
  38.    if(dead)
  39.    {
  40.       deadcount++;
  41.       if(deadcount > 1000)
  42.       {
  43.          this.removeMovieClip();
  44.          unloadMovie(this);
  45.       }
  46.       gotoAndStop("die");
  47.       this._x -= _hitomi.speed;
  48.       return undefined;
  49.    }
  50.    lastdecision++;
  51.    onDie();
  52.    onWalk();
  53.    doCalcs();
  54.    var _loc3_ = fallback();
  55.    if(_loc3_ == undefined)
  56.    {
  57.       _loc3_ = 0;
  58.    }
  59.    var _loc4_ = _root.hitomi.speed;
  60.    checkHits();
  61.    decide();
  62.    this._x -= _loc4_;
  63.    this._x += _loc3_;
  64.    if(!walking && !attacking && !turning && !recieving)
  65.    {
  66.       unwalk();
  67.       gotoAndStop("stand");
  68.    }
  69. };
  70. checkHits = function()
  71. {
  72.    if(this.hitarea.hitTest(_hitomi.hitarea))
  73.    {
  74.       onHit();
  75.    }
  76.    if(_root.hitomi.hitTest(_X + club._x * getDirection(),_Y + club._y,true))
  77.    {
  78.       _root.hitomi.recieveHit(this);
  79.    }
  80.    if(_root.hitomi.hitTest(_X + (club._x + 3) * getDirection(),_Y + club._y,true))
  81.    {
  82.       _root.hitomi.recieveHit(this);
  83.    }
  84.    if(_root.hitomi.hitTest(_X + (club._x - 3) * getDirection(),_Y + club._y,true))
  85.    {
  86.       _root.hitomi.recieveHit(this);
  87.    }
  88. };
  89. doCalcs = function()
  90. {
  91.    if(!(walking || slashing || jumping || parrying || turning || recieving))
  92.    {
  93.       ki += regen_rate;
  94.    }
  95.    if(ki > total_ki)
  96.    {
  97.       ki = total_ki;
  98.    }
  99.    if(hp > total_hp)
  100.    {
  101.       hp = total_hp;
  102.    }
  103.    if(ki < 0)
  104.    {
  105.       ki = 0;
  106.    }
  107.    if(hp < 1)
  108.    {
  109.       hp = 0;
  110.       die();
  111.    }
  112.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  113.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  114. };
  115. getDirection = function()
  116. {
  117.    if(orig_scale == _xscale)
  118.    {
  119.       return 1;
  120.    }
  121.    return -1;
  122. };
  123. bombHit = function(hit_by, dmg, pushf)
  124. {
  125.    hp -= dmg;
  126. };
  127. onHit = function()
  128. {
  129.    _root.hitcount = _root.hitcount + 1;
  130.    if(_root.hitcount > 1000)
  131.    {
  132.       _root.hitcount = 0;
  133.    }
  134.    hp -= _hitomi.damage;
  135.    _root._score += _hitomi.damage;
  136.    var _loc3_ = _root.attachMovie("mc_blood01","blood" + hitcount,6000 + hitcount);
  137.    _loc3_._rotation = random(360);
  138.    var _loc4_ = random(150) + 100;
  139.    _loc3_._xscale = _loc4_;
  140.    _loc3_._yscale = _loc4_;
  141.    if(_hitomi.side == "R")
  142.    {
  143.       _loc3_._x = _hitomi._x + _hitomi.hitarea._x;
  144.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  145.    }
  146.    else
  147.    {
  148.       _loc3_._x = _hitomi._x - _hitomi.hitarea._x;
  149.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  150.    }
  151.    fall_distance = _hitomi.pushback * 2;
  152.    fallback = function()
  153.    {
  154.       fall_distance--;
  155.       if(fall_distance < 1)
  156.       {
  157.          delete this.fallback;
  158.          fall_distance = 0;
  159.          return 0;
  160.       }
  161.       return _hitomi.getDirection() * (fall_distance / 2);
  162.    };
  163.    soundsList = ["loud_metal_hit","blow01","beat","cabasa","zddd1kick1","zddd1kick2","zddd1tamb"];
  164.    playSound(soundsList);
  165. };
  166. die = function()
  167. {
  168.    _root.removePic(pic);
  169.    dead = true;
  170.    walking = false;
  171.    slashing = false;
  172.    attacking = false;
  173.    speed = 0;
  174.    gotoAndStop("die");
  175.    play();
  176. };
  177. decide = function()
  178. {
  179.    if(dead)
  180.    {
  181.       return undefined;
  182.    }
  183.    if(!walking && !attacking || lastdecision > 250)
  184.    {
  185.       lastdecision = 0;
  186.       var _loc2_ = random(20);
  187.       attacking = false;
  188.       if(_loc2_ == 0)
  189.       {
  190.          walk_distance = random(walkdistance) + 6;
  191.          walk();
  192.          return undefined;
  193.       }
  194.       var _loc1_ = Math.abs(_hitomi._x - _X);
  195.       if(_loc2_ < 3)
  196.       {
  197.          if(_loc1_ < 10 || _loc1_ > reach)
  198.          {
  199.             if(_hitomi._x < _X)
  200.             {
  201.                left();
  202.             }
  203.             else
  204.             {
  205.                right();
  206.             }
  207.             return undefined;
  208.          }
  209.       }
  210.       if(_loc1_ < reach)
  211.       {
  212.          if(_hitomi._x > _X && side == "L")
  213.          {
  214.             turn("R");
  215.          }
  216.          if(_hitomi._x < _X && side == "R")
  217.          {
  218.             turn("L");
  219.          }
  220.          attack();
  221.          return undefined;
  222.       }
  223.       if(_loc1_ < hit2_reach)
  224.       {
  225.          if(_hitomi._x > _X && side == "L")
  226.          {
  227.             turn("R");
  228.          }
  229.          if(_hitomi._x < _X && side == "R")
  230.          {
  231.             turn("L");
  232.          }
  233.          attack2();
  234.          return undefined;
  235.       }
  236.       unwalk();
  237.       gotoAndStop("stand");
  238.    }
  239. };
  240. attack = function()
  241. {
  242.    if(!attacking)
  243.    {
  244.       if(ki < ki_cost)
  245.       {
  246.          walking = false;
  247.          attacking = false;
  248.          walk_distance = random(walkdistance) + 6;
  249.          walk();
  250.          return undefined;
  251.       }
  252.       walking = false;
  253.       speed = 0;
  254.       attacking = true;
  255.       ki -= ki_cost;
  256.       gotoAndStop("hit");
  257.       play();
  258.    }
  259. };
  260. attack2 = function()
  261. {
  262.    if(!attacking)
  263.    {
  264.       if(ki < ki_cost)
  265.       {
  266.          walking = false;
  267.          attacking = false;
  268.          walk_distance = random(walkdistance) + 6;
  269.          walk();
  270.          return undefined;
  271.       }
  272.       walking = false;
  273.       speed = 0;
  274.       attacking = true;
  275.       ki -= ki_cost;
  276.       gotoAndStop("hit2");
  277.       play();
  278.    }
  279. };
  280. if(!init)
  281. {
  282.    side = "L";
  283.    orig_scale = _xscale;
  284.    init = true;
  285. }
  286. right = function()
  287. {
  288.    turn("R");
  289. };
  290. left = function()
  291. {
  292.    turn("L");
  293. };
  294. turn = function(sideto)
  295. {
  296.    if(!sideto)
  297.    {
  298.       if(side == "L")
  299.       {
  300.          sideto = "R";
  301.       }
  302.       else
  303.       {
  304.          sideto = "L";
  305.       }
  306.    }
  307.    if(side != sideto)
  308.    {
  309.       if(!jumping)
  310.       {
  311.          turnTo = sideto;
  312.          walking = false;
  313.          jumping = false;
  314.          parrying = false;
  315.          attacking = false;
  316.          if(sideto == "L")
  317.          {
  318.             _xscale = orig_scale;
  319.          }
  320.          else
  321.          {
  322.             _xscale = - orig_scale;
  323.          }
  324.          side = sideto;
  325.       }
  326.    }
  327.    else
  328.    {
  329.       turning = false;
  330.       walk_distance = random(walkdistance) + 6;
  331.       walk();
  332.    }
  333. };
  334. walk = function()
  335. {
  336.    if(walking || attacking || jumping || parrying || turning || dead)
  337.    {
  338.       return undefined;
  339.    }
  340.    walking = true;
  341.    gotoAndStop("walk");
  342.    play();
  343.    this.count = 0;
  344.    this.onWalk = function()
  345.    {
  346.       count++;
  347.       walking = true;
  348.       if(side == "R")
  349.       {
  350.          _X = _X + 1.5;
  351.       }
  352.       else
  353.       {
  354.          _X = _X - 1.5;
  355.       }
  356.       if(count > Math.abs(walk_distance))
  357.       {
  358.          delete this.onWalk;
  359.          walking = false;
  360.          unwalk();
  361.       }
  362.    };
  363. };
  364. unwalk = function()
  365. {
  366.    if(walking && !dead)
  367.    {
  368.       walking = false;
  369.       speed = 0;
  370.       gotoAndStop("stand");
  371.    }
  372. };
  373. playSound = function(ids)
  374. {
  375.    _root.sounds.playSound(ids);
  376. };
  377. stop();
  378.